#include <stdio.h>
#include <string.h>
#include <stdlib.h>


#define LEN 100

int countByte(char *p1,char *p2)
{
    int count = 0;
    char search = *p2;
    while(*p1 != '\0')
    {
        if (search == *p1)
        {
            count++;
        }
        p1++;
    }
    return count;
    
}

int main()
{   
    char *s1 = (char *)malloc(LEN);
    if (NULL == s1)
    {
        printf("malloc error!\n");
        exit(1);
    }
    memset(s1,0,LEN);

    char *s2 = (char *)malloc(LEN);
    if (NULL == s2)
    {
        printf("malloc error!\n");
        exit(1);
    }
    memset(s2,0,LEN);

    int count;

    printf("请输入字符：\n");
    scanf("%s",s1);
    printf("你输入的字符串为：%s\n",s1);

    printf("请输入您想查找的字符：");
    scanf("%s",s2);
    printf("\n");
    
    count = countByte(s1,s2);
    printf("字符 %s 在字符串中出现的次数为：%d\n",s2,count);

    free(s1);
    free(s2);

    return 0;
}